/*******************************************************************************
 * 版权：北京润尼尔网络科技有限公司，保留所有版权<br>
 * 版本：v1.0.0<br>
 * 文件：DeviceEditPart.js<br>
 * 日期：2016年9月20日<br>
 * 作者:王志远<br>
 * 功能：器件编辑件<br>
 *
 * 修改记录：<br>
 * 日期 描述 更新功能<br>
 ******************************************************************************/

window.makeNamespace(window, "Rainier.UI.V2");

/**
 * 类型名称：Rainier.UI.V2.CompositeEditPart<br>
 * 类型功能：器件编辑件<br>
 */
Rainier.UI.V2.DeviceEditPart = Rainier.UI.V2.CompositeEditPart.extend({
  NAME: "Rainier.UI.V2.DeviceEditPart",

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.init<br>
   * 函数功能：构造函数<br>
   * 异常信息：无<br>
   */
  init: function () {
    this._super();
    // this.tabComponent = new Rainier.UI.V2.AppTabComponent();
    this.messageNum = 0;
  },

  // onFigureClick : function(emitter,figure){
  // 	var model = this.getModel();

  // 	if(model){
  // 		if(model instanceof Rainier.UI.V2.SwitchModel){
  // 			model.changeState();
  // 		}
  // 	}

  // 	if(model){
  // 		if(model instanceof Rainier.UI.V2.CustomModel){
  // 			model.changeState();
  // 		}
  // 	}
  // },

  onFigureDbclick: function (emitter, figure) {
    // var model = this.getModel();
    // debugger;
    // if (model) {
    //   if (model instanceof Rainier.UI.V2.VirtualModel) {
    //     model.startCvi();
    //   }
    //   if (model instanceof Rainier.UI.V2.CustomModel) {
    //     var modelId = model.getProperty().modelProperty.modelId;
    //     if (modelId === "CustomPart") {
    //       var activeEditor = window.app.getContext().getActiveEditor();
    //       var dialog = new Rainier.UI.V2.UploadPictureDialog(this.figure);
    //     }
    //   }
    //   // else if(model instanceof Rainier.UI.V2.PmsModel){
    //   // 	//福州大学特殊处理
    //   // 	var uiProperty = model.getProperty().uiProperty;
    //   // 	if (uiProperty.waveimage) {
    //   // 		var height = uiProperty.waveheight;
    //   // 		var width = uiProperty.wavewidth;
    //   // 		var title = model.getProperty().modelProperty.componentName;
    //   // 		var dialog = new Rainier.UI.V2.WaveDialog({height:height,width:width,image:uiProperty.waveimage,title:title});
    //   // 		dialog.dialog.open();
    //   // 	}
    //   // }
    // }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.onFigureContextMenu<br>
   * 函数功能：当图元右键菜单时触发<br>
   * 参数输入：emitter : canvas图元对象<br>
   * 参数输入：figure  : 触发事件时，传递的参数(包含：figure图元、x值，y值，ctrl值，shfit值)<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  onFigureContextMenu: function (emitter, figure) {
    if (figure.figure instanceof draw2d.Figure) {
      var canvas = figure.figure.getCanvas();
      var selection = canvas.getSelection().getAll();
      if (!selection.contains(figure.figure)) {
        selection.each(function (index, select) {
          var selectionStuff = window.AppContext.getSelectionStuff();
          var ctx = selectionStuff.activeEditor.context;
          var editPart = ctx.findEditPartByFigure(select);
          editPart.model.deactive();
        });
        var point = canvas.fromCanvasToDocumentCoordinate(figure.x, figure.y);
        canvas.setCurrentSelection(figure.figure);
        canvas.mouseDownX = point.x;
        canvas.mouseDownY = point.y;
      }
      var canvasEditPart = canvas.context.findEditPartByFigure(canvas);
      var deviceMenu = new Rainier.UI.V2.DeviceMenu(canvasEditPart, figure);
      deviceMenu.show();
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.createFigure<br>
   * 函数功能：创建图元<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  createFigure: function () {
    var model = this.model;
    var prop = model.property;
    var label = prop.modelProperty.label;
    var txt = label.replace(/-/g, ".");
    //添加的节点的父节点
    var nodeParent = null;

    // 创建流程框
    var typeName = model.property.modelProperty.typeName.substring(0, 9);
    if (!this.figure && typeName === "TextModel") {
      if (model.property.modelProperty.typeName === "TextModelJson" || model.property.modelProperty.typeName === "TextModelJsonPara") {
        var thisFigure = new Rainier.UI.V2.TextFigure(prop);
      }
      if (model.property.modelProperty.typeName === "TextModelOval") {
        var thisFigure = new Rainier.UI.V2.TextOvalFigure(prop);
      }
      if (model.property.modelProperty.typeName === "TextModelDiamond") {
        var thisFigure = new Rainier.UI.V2.TextDiamondFigure(prop);
      }
      //设置器件Label
      thisFigure.setSymbolLabelFigure(
        {
          text: txt,
          fontSize: 16,
          bold: true,
          fontColor: "#000000",
          visible: false,
        },
        "Rainier.UI.V2.DeviceLabelLocator",
        20,
        -20
      );
      this.figure = thisFigure;
      this.fillFigure();
      this.figure.on("change:text", $.proxy(this.textValueChanged, this));
      this.figure.on("resize", $.proxy(this.textFigureResize, this));
      if (prop.modelProperty) {
        var showInfo = prop.modelProperty.showInfo;
        if (showInfo) {
          var showLabel = showInfo.showLabel;

          if (showLabel && showLabel.showable && showLabel.visiable) {
            this.figure.showLabel();
          }
        }

        //添加器件id
        if (!prop.modelProperty.id) {
          prop.modelProperty.id = new Date().getTime();
        }
        return this.figure;
      }
    }

    // 创建自定义文本框
    if (!this.figure) {
      if (typeof Rainier.UI.V2.CustomTextModel !== "undefined" && model instanceof Rainier.UI.V2.CustomTextModel) {
        var thisFigure = new Rainier.UI.V2.CustomTextFigure(prop);
        this.figure = thisFigure;
        thisFigure.setSymbolLabelFigure(
          {
            text: txt,
            fontSize: 16,
            bold: true,
            fontColor: "#2E4555",
            visible: false,
          },
          "Rainier.UI.V2.DeviceLabelLocator",
          20,
          -20
        );
        this.figure = thisFigure;
        this.fillFigure();
        this.figure.on("change:text", $.proxy(this.textChanged, this));
        if (prop.modelProperty) {
          var showInfo = prop.modelProperty.showInfo;
          if (showInfo) {
            var showLabel = showInfo.showLabel;

            if (showLabel && showLabel.showable && showLabel.visiable) {
              this.figure.showLabel();
            }
          }
        }
        return this.figure;
      }
    }

    if (!this.figure) {
      //创建box图元
      var thisFigure = new Rainier.UI.V2.DeviceBoxFigure(prop);

      // 自定义模型（可上传图片）
      if (model instanceof Rainier.UI.V2.CustomModel) {
        thisFigure = new Rainier.UI.V2.CustomFigure(prop);
      }

      // 加号
      if (model instanceof Rainier.UI.V2.PlusModel) {
        thisFigure = new Rainier.UI.V2.PlusFigure(prop);
      }

      //填充图片
      var imageProperty = {};
      imageProperty.width = prop.imageProperty.width;
      imageProperty.height = prop.imageProperty.height;
      imageProperty.svg = prop.imageProperty.svg;

      //设置器件Label
      thisFigure.setSymbolLabelFigure(
        {
          text: prop.modelProperty.label,
          fontSize: 14,
          bold: true,
          fontColor: "#000000",
          visible: false,
        },
        "Rainier.UI.V2.DeviceLabelLocator",
        thisFigure.width / 2 + 5,
        -20
      );

      //设置参数标签
      thisFigure.setParameterFigure(
        {
          text: prop.modelProperty.label,
          fontSize: 14,
          bold: true,
          fontColor: "#000000",
          visible: false,
        },
        "Rainier.UI.V2.DeviceLabelLocator",
        thisFigure.width + 5,
        thisFigure.height / 2 - 10
      );

      //设置参数标签
      thisFigure.setDeviceNameFigure(
        {
          text: prop.modelProperty.componentName,
          fontSize: 14,
          bold: true,
          fontColor: "#000000",
          visible: false,
        },
        "Rainier.UI.V2.DeviceLabelLocator",
        0,
        thisFigure.height + 10
      );

      //设置参数标签
      thisFigure.setDeviceEngNameFigure(
        {
          text: prop.modelProperty.engName,
          fontSize: 14,
          bold: true,
          fontColor: "#000000",
          visible: false,
        },
        "Rainier.UI.V2.DeviceLabelLocator",
        0,
        thisFigure.height + 25
      );

      this.figure = thisFigure;
      var inputs = model.getInputPorts();
      inputs.each($.proxy(this.addPortFigure, this));

      var outputs = model.getOutputPorts();
      outputs.each($.proxy(this.addPortFigure, this));

      var hybirds = model.getHybridPorts();
      hybirds.each($.proxy(this.addPortFigure, this));
    }

    this.fillFigure();
    var paraString = this.refreshParameters();

    this.figure.unshowPortNumber();
    this.figure.unshowPortSymbol();
    this.figure.unshowLabel();
    this.figure.unshowParameter();
    this.figure.unshowDeviceName();
    this.figure.unshowDeviceEngName();

    var context = this.getParent().context;
    var showDevice = context.menuItemUsedInfo.deviceInfoUsed;
    var deviceShowAll = context.menuItemUsedInfo.deviceShowAll;

    if (paraString && showDevice) {
      this.figure.showParameter();
    }
    if (model instanceof Rainier.UI.V2.CustomModel || model instanceof Rainier.UI.V2.PlusModel) {
      this.figure.on("resize", $.proxy(this.CustomFigureResize, this));
      // this.figure.on("resize",		$.proxy(this.onFigureResize,this));
    }

    if (prop.modelProperty) {
      var showInfo = prop.modelProperty.showInfo;
      if (showInfo && showDevice) {
        var showLabel = showInfo.showLabel;
        var showPinNumber = showInfo.showPinNumber;
        var showPinSymbol = showInfo.showPinSymbol;
        var showComponentName = showInfo.showComponentName;
        var showEngName = showInfo.showEngName;
        if (showLabel && showLabel.showable && showLabel.visiable) {
          this.figure.showLabel();
        }

        if ((showPinNumber && showPinNumber.showable && showPinNumber.visiable) || (deviceShowAll && showPinSymbol && showPinSymbol.showable)) {
          this.figure.showPortNumber();
        }

        if ((showPinSymbol && showPinSymbol.showable && showPinSymbol.visiable) || (deviceShowAll && showPinSymbol && showPinSymbol.showable)) {
          this.figure.showPortSymbol();
        }

        if (
          (showComponentName && showComponentName.showable && showComponentName.visiable) ||
          (deviceShowAll && showComponentName && showComponentName.showable)
        ) {
          this.figure.showDeviceName();
        }

        if ((showEngName && showEngName.showable && showEngName.visiable) || (deviceShowAll && showEngName && showEngName.showable)) {
          this.figure.showDeviceEngName();
        }
      }
    }
    return this.figure;
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.refreshParameters<br>
   * 函数功能：刷新参数显示<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  refreshParameters: function () {
    var paraString = "";
    var paraList = this.findVisibleParameters();
    paraString = this.formatParameters(paraList);
    if (this.figure.parameterFigure) {
      this.figure.parameterFigure.setText(paraString);
    }
    return paraString;
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.formatParameters<br>
   * 函数功能：格式化需要显示的参数<br>
   * 参数输入：paraList:draw2d.util.ArrayList(需要显示参数列表)<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  formatParameters: function (paraList) {
    if (paraList.getSize() === 0) {
      return "";
    }
    if (paraList.getSize() === 1) {
      var para = paraList.get(0);
      return para.value.value + para.unit.unitType;
    }

    var str = "";
    paraList.each(function (i, para) {
      str += para.name + "=" + para.value.value + para.unit.unitType + " ";
    });
    return str;
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.findVisibleParameters<br>
   * 函数功能：查找可以显示的参数列表<br>
   * 函数返回：draw2d.util.ArrayList<br>
   * 异常信息：无<br>
   */
  findVisibleParameters: function () {
    if (!this.model) {
      debugger;
      return;
    }
    if (!this.model.property.modelProperty) {
      debugger;
      return;
    }
    if (!this.model.property.modelProperty.additional) {
      debugger;
      return;
    }
    if (!this.model.property.modelProperty.additional.spiceProperties) {
      debugger;
      return;
    }

    var parameters = this.model.property.modelProperty.additional.spiceProperties;
    var list = new draw2d.util.ArrayList();
    for (var i = 0; i < parameters.length; i++) {
      var para = parameters[i];
      if (para.showInfo) {
        if (para.showInfo.showable && para.showInfo.visiable) {
          list.add(para);
        }
      }
    }
    return list;
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.handleModelEvent<br>
   * 函数功能：处理模型事件<br>
   * 参数输入：modelEvent:模型事件<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  handleModelEvent: function (modelEvent) {
    var eventName = modelEvent.getEventName();
    var oldValue = modelEvent.getOldValue();
    var newValue = modelEvent.getNewValue();
    var figure = this.getFigure();
    var modelPro = this.getModel().property.modelProperty;

    switch (eventName) {
      //DeviceModel事件定义：修改标签，label属性值改变
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_LABEL_CHANGED: {
        if (newValue.needCommandRequest) {
          var handler = new Rainier.UI.V2.DeviceModelEventHandlerSetLabel();
          handler.setEditPart(this);
          handler.setOldLabel(oldValue.label);
          handler.setNewLabel(newValue.label);
          this.figure.getCanvas().getCommandStack().execute(handler);
        } else {
          figure.symbolLabelFigure.setText(newValue.label);
        }
        return;
      }

      //DeviceModel事件定义：显示标签
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_SHOW_LABEL: {
        var showInfo = modelPro.showInfo;
        if (showInfo) {
          if (showInfo.showLabel && showInfo.showLabel.showable) {
            figure.showLabel();
            return;
          }
          if (showInfo.showLabel && showInfo.showLabel.showable == false) {
            figure.unshowLabel();
          }
        }
        return;
      }

      //DeviceModel事件定义：隐藏标签
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_HIDE_LABEL: {
        var showInfo = modelPro.showInfo;
        if (showInfo) {
          if (showInfo.showLabel && showInfo.showLabel.showable) {
            figure.unshowLabel();
            return;
          }
          if (showInfo.showLabel && showInfo.showLabel.showable == false) {
            figure.unshowLabel();
          }
        }
        return;
      }

      //DeviceModel事件定义：显示引脚的编号
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_SHOW_PIN_NUMBER: {
        var showInfo = modelPro.showInfo;
        if (showInfo) {
          if (showInfo.showPinNumber && showInfo.showPinNumber.showable && showInfo.showPinNumber.visiable) {
            figure.showPortNumber();
            return;
          }
          if (showInfo.showPinNumber) {
            figure.unshowPortNumber();
          }
        }
        return;
      }

      //DeviceModel事件定义：隐藏引脚的编号
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_HIDE_PIN_NUMBER: {
        if (showInfo) {
          if (showInfo.showPinNumber) {
            figure.unshowPortNumber();
          }
        }
        return;
      }

      //DeviceModel事件定义：显示引脚的符号
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_SHOW_PIN_SYMBOL: {
        var showInfo = modelPro.showInfo;
        if (showInfo) {
          if (showInfo.showPinSymbol && showInfo.showPinSymbol.showable && showInfo.showPinSymbol.visiable) {
            figure.showPortSymbol();
            return;
          }
        }
        if (showInfo) {
          if (showInfo.showPinNumber) {
            figure.unshowPortSymbol();
          }
        }
        return;
      }

      //DeviceModel事件定义：隐藏引脚的符号
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_HIDE_PIN_SYMBOL: {
        if (showInfo) {
          if (showInfo.showPinNumber) {
            figure.unshowPortSymbol();
          }
        }
        return;
      }

      //DeviceModel事件定义：修改名称，componentName属性值改变
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_COMPONENTNAME_CHANGED: {
        if (newValue.needCommandRequest) {
          var handler = new Rainier.UI.V2.DeviceModelEventHandlerSetDevName();
          handler.setEditPart(this);
          handler.setOldDevName(oldValue.componentName);
          handler.setNewDevName(newValue.componentName);
          this.figure.getCanvas().getCommandStack().execute(handler);
        } else {
          figure.devNameFigure.setText(newValue.componentName);
        }
        return;
      }

      //DeviceModel事件定义：显示设备名称
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_SHOW_DEV_NAME: {
        var showInfo = modelPro.showInfo;
        if (showInfo) {
          if (showInfo.showComponentName && showInfo.showComponentName.showable && showInfo.showComponentName.visiable) {
            figure.showDeviceName();
            return;
          }
        }
        figure.unshowDeviceName();
        return;
      }

      //DeviceModel事件定义：隐藏设备名称
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_HIDE_DEV_NAME: {
        var showInfo = modelPro.showInfo;
        if (showInfo) {
          if (showInfo.showComponentName.showable || showInfo.showComponentName.visiable) {
            figure.unshowDeviceName();
            return;
          }
        }
      }

      //DeviceModel事件定义：修改英文名称，英文名称属性值改变
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_ENGNAME_CHANGED: {
        if (newValue.needCommandRequest) {
          console.log(newValue);
          console.log(oldValue);
          var handler = new Rainier.UI.V2.DeviceModelEventHandlerSetDevEngName();
          handler.setEditPart(this);
          handler.setOldDevEngName(oldValue.engName);
          handler.setNewDevEngName(newValue.engName);
          this.figure.getCanvas().getCommandStack().execute(handler);
        } else {
          figure.devEngNameFigure.setText(newValue.engName);
        }
        return;
      }
      //DeviceModel事件定义：显示设备英文名称
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_SHOW_ENG_NAME: {
        var showInfo = modelPro.showInfo;
        if (showInfo) {
          if (showInfo.showEngName && showInfo.showEngName.showable && showInfo.showEngName.visiable) {
            figure.showDeviceEngName();
            return;
          }
        }
        figure.unshowDeviceEngName();
        return;
      }

      //DeviceModel事件定义：隐藏设备英文名称
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_HIDE_ENG_NAME: {
        var showInfo = modelPro.showInfo;
        if (showInfo) {
          if (showInfo.showEngName.showable || showInfo.showEngName.visiable) {
            figure.unshowDeviceEngName();
            return;
          }
        }
      }

      //DeviceModel事件定义：修改模型参数
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_PARA_VALUE_CHANGED: {
        this.refreshParameters();
        return;
      }

      //DeviceModel事件定义：显示模型参数
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_SHOW_PARA: {
        var str = this.refreshParameters();
        if (str) {
          figure.showParameter();
        }
        return;
      }

      //DeviceModel事件定义：隐藏模型参数
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_HIDE_PARA: {
        var str = this.refreshParameters();
        if (str) {
          figure.showParameter();
        } else {
          figure.unshowParameter();
        }
        return;
      }

      //DeviceModel事件定义：显示所有模型参数
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_SHOW_ALL_PARA: {
        figure.showParameter();
        return;
      }

      //DeviceModel事件定义：隐藏所有模型参数
      case Rainier.UI.V2.DeviceModel.DEVICE_MODEL_EVENT_HIDE_ALL_PARA: {
        figure.unshowParameter();
        return;
      }

      case Rainier.UI.V2.DynamicModel.DYNAMIC_MODEL_EVENT_CHANGE_STATE: {
        this.onDynamicChange(newValue);
        return;
      }
    }

    this._super(modelEvent);
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.onDynamicChange<br>
   * 函数功能：刷新动态元件(图片、文字等)<br>
   * 参数输入：data：动态参数<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  onDynamicChange: function (data) {
    var _this = this;
    var subImageList = this.figure.subImageList;
    var subTextList = this.figure.subTextList;
    if (subImageList || subTextList) {
      var model = this.getModel();
      var property = model.getProperty();
      var uiProperty = property.uiProperty;
      var modelPro = property.modelProperty;

      var refreshSub = function (index, sub) {
        var condition = sub.condition;
        if (condition !== undefined) {
          var spice = model.replaceSpiceModel(condition, modelPro);
          var regZero = new RegExp("(\\[V\\(0\\)\\])", "g");
          spice = spice.replace(regZero, "0");
          spice = _this.translateString("data", spice);
          //检测@@内容，数码管特例修改
          if (spice.indexOf("@") >= 0) {
            spice = _this.translateNixieTube(data, model, spice);
          }
          //TODO:动态元件显示规则
          try {
            //直流、交流的特殊处理 TODO:添加匹配规则  。。。淡淡的忧桑
            var ret = null;
            if (model instanceof Rainier.UI.V2.VirtualModel) {
              var cviInfo = model.cviInfo;
              if (cviInfo) {
                ret = model.cviResult; //tranlateToDynamicText(data,spice);//产品要求同步，取消自定算法。。。。
              } else {
                ret = "";
              }
              _this.messageNum++;
            } else {
              ret = eval(spice);
              _this.messageNum = 100;
            }

            if (sub.image) {
              sub.visible = ret;
            } else {
              sub.text = ret;
            }
          } catch (e) {
            console.log(e);
          }
        }
      };

      subImageList.each(refreshSub);
      subTextList.each(refreshSub);
      if (this.figure.updateDynamicSet) {
        if (_this.messageNum >= 50) {
          this.figure.updateDynamicSet();
          _this.messageNum = 0;
        }
      }
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.translateString<br>
   * 函数功能：替换[x]为(data[x] == undefined)?0:data[x]<br>
   * 参数输入：spice ： 字符串<br>
   * 参数输出：无<br>
   * 函数返回：替换后字符串<br>
   * 异常信息：无<br>
   */
  translateString: function (data, spice) {
    var reg = new RegExp("\\[(.+?)\\]", "g");
    spice = spice.replace(reg, "((" + data + "['$1'] == undefined)?0:" + data + "['$1'])");
    return spice;
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.translateNixieTube<br>
   * 函数功能：匹配数码管特殊规则<br>
   * 参数输入：spice ： 字符串<br>
   * 参数输出：无<br>
   * 函数返回：替换后字符串<br>
   * 异常信息：无<br>
   */
  translateNixieTube: function (data, model, spice) {
    var index = spice.indexOf("@");
    var spaceIndex = spice.indexOf("@", index + 1);
    var replaceStr = spice.substr(index, spaceIndex - index + 1);
    var reg = new RegExp("(" + replaceStr + ")", "g");

    var contentKey = spice.substr(index + 1, spaceIndex - index - 1);
    var count = 0;
    var portList = model.getHybridPorts().asArray();
    var length = portList.length;
    $.each(portList, function (i, port) {
      var node = port.getProperty().modelProperty.node;
      var value = 0;
      if (node > 0) {
        value = data["V(" + node + ")"] > 2.5 ? 1 : 0;
      }
      count += value * Math.pow(2, length - i - 1);
    });
    count = count.toString(16);

    spice = "[" + contentKey + "].indexOf('" + count + "') < 0";

    return spice;
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.refreshFigure<br>
   * 函数功能：完成figure的刷新功能<br>
   * 参数输入：propertyKey ：修改参数的key值<br>
   * 参数输入：propertyValue ：修改参数的value值<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  refreshFigure: function (propertyKey, propertyValue) {
    if (propertyKey == "label") {
      var symbolLabelFigure = this.figure.symbolLabelFigure;
      symbolLabelFigure.setText(propertyValue);
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.addPortFigure<br>
   * 函数功能：添加端口数字/符号引脚<br>
   * 参数输入：i：index；port：端口<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  addPortFigure: function (i, port) {
    var portProperty = port.property;
    var portLocator = portProperty.modelProperty.locator;
    var symbolLocator = portProperty.modelProperty.symbolLocator;
    if (symbolLocator) {
      this.figure.addPortSymbolLabelFigure(
        {
          text: portProperty.modelProperty.symbol,
          symboltype: portProperty.modelProperty.symboltype,
          fontSize: 8,
          fontColor: "#FF0000",
          angle: 0,
        },
        symbolLocator.type,
        symbolLocator.x - 6,
        symbolLocator.y - 9
      );
    }
    this.figure.addPortNumberLabelFigure(
      {
        text: portProperty.modelProperty.id,
        fontSize: 8,
        fontColor: "#FF00FF",
        angle: 0,
      },
      portLocator.type,
      portLocator.defaultX,
      portLocator.defaultY
    );
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.textValueChanged<br>
   * 函数功能：流程框中的值改变，相应的figure需进行变化<br>
   * 参数输入：eventSource, paramObj<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  textValueChanged: function (eventSource, paramObj) {
    return; //只针对移动端，双击不想编辑文本框
    console.log(paramObj);
    var model = this.getModel();
    //改变之前的宽高
    var oldWidth = model.getProperty().uiProperty.width;
    var oldHeight = model.getProperty().uiProperty.height;
    model.getProperty().modelProperty.text = paramObj.value;
    var label = this.figure.getLabel();
    this.figure.width = label.cachedWidth + 30;
    this.figure.height = label.cachedHeight + 25;
    model.getProperty().uiProperty.width = label.cachedWidth + 30;
    model.getProperty().uiProperty.height = label.cachedHeight + 25;

    this.setModel(model);
    this.figure.repaint();
    // this.figure.installEditPolicy(new draw2d.policy.figure.RectangleSelectionFeedbackPolicy());

    // //检测它是否有兄弟集
    // var parent = model.property.modelProperty.parent;
    // var brother,son;
    // if(parent){
    // 	var parentModel = this.getModelById(parent);
    // 	var children = parentModel.property.modelProperty.children;
    // 	brother = children.length;
    // }else{
    // 	brother = -1;
    // }

    // //检测它是否有子集
    // var children = model.property.modelProperty.children;
    // son = children.length;

    //当子集不唯一时或者宽度比原来大时执行
    // if(model.property.uiProperty.width > oldWidth){
    // 	if(model.property.modelProperty.typeName!='TextModelJsonPara'){
    // 		this.refreshTree(model,oldWidth,oldHeight);
    // 	}
    // 	else{
    // 		this.refreshTreePara(model,oldWidth,oldHeight);
    // 	}
    // }else{
    // 	var modelwidth = model.property.uiProperty.width;
    // 	var distanceX = (modelwidth - oldWidth)/2;
    // 	this.moveChild(model,(-1)*distanceX);
    // }

    if (model.property.modelProperty.typeName != "TextModelJsonPara") {
      this.refreshTree(model, oldWidth, oldHeight);
    } else {
      this.refreshTreePara(model, oldWidth, oldHeight);
    }

    var width = model.getProperty().uiProperty.width;
    var height = model.getProperty().uiProperty.height;
    if (this.figure.cachedPorts.data[0]) {
      this.figure.cachedPorts.data[0].x = 0;
      this.figure.cachedPorts.data[0].y = height / 2;
    }
    if (this.figure.cachedPorts.data[1]) {
      this.figure.cachedPorts.data[1].x = width;
      this.figure.cachedPorts.data[1].y = height / 2;
    }
    if (this.figure.cachedPorts.data[2]) {
      this.figure.cachedPorts.data[2].x = width / 2;
      this.figure.cachedPorts.data[2].y = 0;
    }
    if (this.figure.cachedPorts.data[3]) {
      this.figure.cachedPorts.data[3].x = width / 2;
      this.figure.cachedPorts.data[3].y = height;
    }
    // 删除后撤销的端口位置设置
    if (this.figure.hybridPorts.data[0]) {
      this.figure.hybridPorts.data[0].locator.x = 0;
      this.figure.hybridPorts.data[0].locator.y = height / 2;
    }
    if (this.figure.hybridPorts.data[1]) {
      this.figure.hybridPorts.data[1].locator.x = width;
      this.figure.hybridPorts.data[1].locator.y = height / 2;
    }
    if (this.figure.hybridPorts.data[2]) {
      this.figure.hybridPorts.data[2].locator.x = width / 2;
      this.figure.hybridPorts.data[2].locator.y = 0;
    }
    if (this.figure.hybridPorts.data[3]) {
      this.figure.hybridPorts.data[3].locator.x = width / 2;
      this.figure.hybridPorts.data[3].locator.y = height;
    }
    this.figure.hybridPorts.each(function (i, port) {
      port.locator.relocate(i, port);
    });

    model.inputPorts.each(function (i, port) {
      port.property.modelProperty.locator.defaultX = port.property.modelProperty.locator.x;
      port.property.modelProperty.locator.defaultY = port.property.modelProperty.locator.y;
    });
    model.outputPorts.each(function (o, port) {
      port.property.modelProperty.locator.defaultX = port.property.modelProperty.locator.x;
      port.property.modelProperty.locator.defaultY = port.property.modelProperty.locator.y;
    });

    //更新树节点信息
    var node = $("#ul-mindMap").tree("find", model.getProperty().modelProperty.id);
    $("#ul-mindMap").tree("update", {
      target: node.target,
      text: model.getProperty().modelProperty.label + " " + paramObj.value,
    });
    console.log("tree");
    //更新tab页面标签
    this.tabComponent.updataTitle(node.id, node.text);
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.textChanged<br>
   * 函数功能：文本框中的值改变，相应的figure需进行变化<br>
   * 参数输入：eventSource, paramObj<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  textChanged: function (eventSource, paramObj) {
    var model = this.getModel();
    // this.figure.getLabel().getText().wrappedTextAttr(paramObj.value,model.getProperty().modelProperty.width);
    model.getProperty().modelProperty.text = paramObj.value;
    this.setModel(model);
    this.figure.repaint();
  },
  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.refreshTree<br>
   * 函数功能：避免主题重合，移动model节点右边兄弟树节点<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  refreshTree: function (model, oldWidth, oldHeight) {
    var modelWidth = model.getProperty().uiProperty.width;
    var modelHeight = model.getProperty().uiProperty.height;

    var distanceX;
    if (modelWidth <= 234 && oldWidth <= 234) {
      distanceX = 0;
    } else if (modelWidth <= 234 && oldWidth >= 234) {
      distanceX = (234 - oldWidth) / 2;
    } else if (modelWidth >= 234 && oldWidth <= 234) {
      distanceX = (modelWidth - 234) / 2;
    } else if (modelWidth >= 234 && oldWidth >= 234) {
      distanceX = (modelWidth - oldWidth) / 2;
    }
    var distanceY = modelHeight - oldHeight;
    this.moveHorizontalLeft(model, -1 * distanceX);
    this.moveHorizontal(model, distanceX);
    this.moveChild(model, (-1 * (modelWidth - oldWidth)) / 2);
    this.moveVertical(model, distanceY);
    // this.refreshConnection();
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.refreshTreePara<br>
   * 函数功能：避免主题重合，移动model节点右边兄弟树节点<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  refreshTreePara: function (model, oldWidth, oldHeight) {
    var modelWidth = model.getProperty().uiProperty.width;
    var modelHeight = model.getProperty().uiProperty.height;
    var distanceX = modelWidth - oldWidth;
    var distanceY = modelHeight - oldHeight;
    this.moveHorizontalPara(model, distanceX);
    this.moveVerticalPara(model, distanceY);
    // this.refreshConnectionPara();
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveHorizontalPara<br>
   * 函数功能：避免主题重合，横向移动model之外其他器件<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveHorizontalPara: function (model, distance) {
    var _this = this;
    var parent = model.property.modelProperty.parent;
    if (parent) {
      var position = model.property.modelProperty.position;
      if (position == "left") {
        var parentModel = this.getModelById(parent);
        var children = parentModel.property.modelProperty.children;
        var modelId = model.property.modelProperty.id;
        var _children = [];
        //除去model及model的子树外，其他全部横向移动
        $.each(children, function (index, child) {
          if (child != modelId) {
            _children.push(child);
          }
        });
        this.moveChildrenX(_children, distance);
        this.moveModel(parent, distance);
      } else if (position == "right") {
        var children = model.property.modelProperty.children;
        this.moveChildrenX(children, distance);
      }
    }
    //根节点
    else {
      var children = model.property.modelProperty.children;
      if (children.length > 0) {
        var rightChildren = [];
        $.each(children, function (index, child) {
          var childModel = _this.getModelById(child);
          var position = childModel.property.modelProperty.position;
          if (position == "right") {
            rightChildren.push(child);
          }
        });
        this.moveChildrenX(rightChildren, distance);
      }
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveVertical<br>
   * 函数功能：避免主题重合，横向移动model之外其他器件<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveVerticalPara: function (model, distance) {
    var parent = model.property.modelProperty.parent;
    //非根节点
    if (parent) {
      //子树以及下方兄弟子树下移
      this.moveTreeVertical(model, distance);
      var _children = model.property.modelProperty.children;
      this.moveChildrenY(_children, distance / 2);
    } else {
      //子树全部下移
      var children = model.property.modelProperty.children;
      this.moveChildrenY(children, distance / 2);
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveTreeVertical<br>
   * 函数功能：下方子树下移<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveTreeVertical: function (model, distance) {
    var _this = this;
    var parent = model.property.modelProperty.parent;
    if (parent) {
      var modelPosition = model.property.modelProperty.position;
      var parentModel = this.getModelById(parent);
      var children = parentModel.property.modelProperty.children;
      var modelId = model.property.modelProperty.id;
      var _children = [];
      //取同边
      $.each(children, function (index, child) {
        var childModel = _this.getModelById(child);
        var position = childModel.property.modelProperty.position;
        if (position == modelPosition) {
          _children.push(child);
        }
      });
      var index = _children.indexOf(modelId);
      var childrenDown = _children.slice(index + 1);
      this.moveChildrenY(childrenDown, distance);
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveChildrenX<br>
   * 函数功能：避免主题重合，横向移动model之外其他器件<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveChildrenX: function (children, distance) {
    for (var i = 0; i < children.length; i++) {
      var _id = children[i];
      var childModel = this.getModelById(_id);
      var uiProperty = childModel.property.uiProperty;
      var x = uiProperty.x;
      var y = uiProperty.y;
      var oldChildX = x + distance;
      var oldChildY = y;
      //更新老孩子位置
      childModel.setPosition(oldChildX, oldChildY, false);
      var _children = childModel.property.modelProperty.children;
      if (_children) {
        this.moveChildrenX(_children, distance);
      }
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveChildrenY<br>
   * 函数功能：避免主题重合，横向移动model之外其他器件<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveChildrenY: function (children, distance) {
    for (var i = 0; i < children.length; i++) {
      var _id = children[i];
      var childModel = this.getModelById(_id);
      var uiProperty = childModel.property.uiProperty;
      var x = uiProperty.x;
      var y = uiProperty.y;
      var oldChildX = x;
      var oldChildY = y + distance;
      //更新老孩子位置
      childModel.setPosition(oldChildX, oldChildY, false);
      var _children = childModel.property.modelProperty.children;
      if (_children) {
        this.moveChildrenY(_children, distance);
      }
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveModel<br>
   * 函数功能：移动单个model<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveModel: function (modelId, distance) {
    var model = this.getModelById(modelId);
    var uiProperty = model.property.uiProperty;
    var x = uiProperty.x;
    var y = uiProperty.y;
    var oldChildX = x + distance;
    var oldChildY = y;
    //更新老孩子位置
    model.setPosition(oldChildX, oldChildY, false);
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveHorizontal<br>
   * 函数功能：避免主题重合，横向移动model之外其他器件<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveHorizontal: function (model, distance) {
    var parent = model.property.modelProperty.parent;
    if (parent) {
      var parentModel = this.getModelById(parent);
      var children = parentModel.property.modelProperty.children;
      var modelId = model.property.modelProperty.id;
      var index = children.indexOf(modelId);
      var childrenRight = children.slice(index + 1);
      this.moveChildren(childrenRight, distance);
      this.moveHorizontal(parentModel, distance);
    }
  },
  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveHorizontal<br>
   * 函数功能：避免主题重合，横向移动不包括model之内的左侧兄弟集<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveHorizontalLeft: function (model, distance) {
    var parent = model.property.modelProperty.parent;
    if (parent) {
      var parentModel = this.getModelById(parent);
      var children = parentModel.property.modelProperty.children;
      var modelId = model.property.modelProperty.id;
      var index = children.indexOf(modelId);
      var childrenRight = children.slice(0, index);
      this.moveChildren(childrenRight, distance);
      this.moveHorizontalLeft(parentModel, distance);
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveHorizontal<br>
   * 函数功能：避免主题重合，横向移动model之外其他器件<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveChildren: function (children, distance) {
    for (var i = 0; i < children.length; i++) {
      var _id = children[i];
      var childModel = this.getModelById(_id);
      var uiProperty = childModel.property.uiProperty;
      var x = uiProperty.x;
      var y = uiProperty.y;
      var oldChildX = x + distance;
      var oldChildY = y;
      //更新老孩子位置
      childModel.setPosition(oldChildX, oldChildY, false);
      var _children = childModel.property.modelProperty.children;
      if (_children) {
        this.moveChildren(_children, distance);
      }
    }
  },
  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveHorizontal<br>
   * 函数功能：避免主题重合，横向移动包括model之内的子集(董行)<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveChild: function (model, distance) {
    var uiProperty = model.property.uiProperty;
    var x = uiProperty.x;
    var y = uiProperty.y;
    var oldChildX = x + distance;
    var oldChildY = y;
    model.setPosition(oldChildX, oldChildY, false);
    var children = model.property.modelProperty.children;

    // for(var i=0;i<children.length;i++){
    // 	var _id = children[i];
    // 	var childModel = this.getModelById(_id);
    // 	var uiProperty = childModel.property.uiProperty;
    // 	var x = uiProperty.x;
    // 	var y = uiProperty.y;
    // 	var oldChildX = x+distance;
    // 	var oldChildY = y;
    // 	//更新老孩子位置
    // 	childModel.setPosition(oldChildX,oldChildY,false);
    // 	var _children = childModel.property.modelProperty.children;
    // 	if(_children){
    // 		this.moveChildren(_children,distance);
    // 	}
    // }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.moveVertical<br>
   * 函数功能：避免主题重合，横向移动model之外其他器件<br>
   * 参数输入：model<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  moveVertical: function (model, distance) {
    var children = model.property.modelProperty.children;
    if (!children || children.length == 0) {
      return;
    }
    for (var i = 0; i < children.length; i++) {
      var _id = children[i];
      var childModel = this.getModelById(_id);
      if (!childModel) {
        return;
      }
      var uiProperty = childModel.property.uiProperty;
      var x = uiProperty.x;
      var y = uiProperty.y;
      var oldChildX = x;
      var oldChildY = y + distance;
      //更新老孩子位置
      childModel.setPosition(oldChildX, oldChildY, false);
      var _model = childModel;
      if (_model) {
        this.moveVertical(_model, distance);
      }
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.getModelById<br>
   * 函数功能：根据主题id查询对应model<br>
   * 参数输入：无<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  getModelById: function (id) {
    var parentModel = this.getParent().getModel();
    var children = parentModel.m_aChildren;
    var model = null;
    if (children) {
      $.each(children, function (index, child) {
        var _id = child.property.modelProperty.id;
        if (_id == id) {
          model = child;
        }
      });
    }
    return model;
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.refreshConnection<br>
   * 函数功能：重新绘制连线<br>
   * 参数输入：无<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  refreshConnection: function () {
    //删除错误连线
    //遍历三次，否则不能删除干净
    activeEditor = app.getContext().getActiveEditor();
    var connections = activeEditor.rootModel.connections.data;
    var _connection = Rainier.UI.V2.Communication.ConnectionModel[0];

    for (var j = 0; j < 3; j++) {
      connections = activeEditor.rootModel.connections.data;
      for (var i = 0; i < connections.length; i++) {
        var connection = connections[i];
        var segments = connection.property.modelProperty.segments;
        if (segments.length > 1) {
          if (segments[0].type == "vertical" || segments[1].type == "horizontal") {
            //确保新线完成再删除错误
            var complete = false;
            //确保id相同
            _connection.uuid = connection.m_sUuid;
            //删除连线
            var sourcePort = connection.sourcePort;
            var targetPort = connection.targetPort;
            var _segment = connection.property.modelProperty.segments;
            var x = _segment[1].end_x;
            var y = _segment[0].start_y;
            if (sourcePort) {
              var segment = _connection.modelProperty.segments;
              segment[1].start_x = x;
              segment[1].start_y = y;
              activeEditor.makeConnection(sourcePort, targetPort, _connection);
            }
            complete = true;
            if (complete) {
              this.getParent().getModel().removeConnection(connection);
            }
          }
        }
      }
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.refreshConnectionPara<br>
   * 函数功能：重新绘制连线<br>
   * 参数输入：无<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  refreshConnectionPara: function () {
    //删除错误连线
    //遍历三次，否则不能删除干净
    activeEditor = app.getContext().getActiveEditor();
    var connections = activeEditor.rootModel.connections.data;
    var _connection = Rainier.UI.V2.Communication.ConnectionModel[0];

    for (var j = 0; j < 3; j++) {
      connections = activeEditor.rootModel.connections.data;
      for (var i = 0; i < connections.length; i++) {
        var connection = connections[i];
        var segments = connection.property.modelProperty.segments;
        if (segments.length > 1) {
          if (segments[0].type == "horizontal" || segments[1].type == "vertical") {
            //确保新线完成再删除错误
            var complete = false;
            //确保id相同
            _connection.uuid = connection.m_sUuid;
            //删除连线
            var sourcePort = connection.sourcePort;
            var targetPort = connection.targetPort;
            var _segment = connection.property.modelProperty.segments;
            var x = _segment[0].start_x;
            var y = _segment[1].end_y;
            if (sourcePort) {
              var segment = _connection.modelProperty.segments;
              segment[1].start_x = x;
              segment[1].start_y = y;
              activeEditor.makeConnection(sourcePort, targetPort, _connection);
            }
            complete = true;
            if (complete) {
              this.getParent().getModel().removeConnection(connection);
            }
          }
        }
      }
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.textFigureResize<br>
   * 函数功能：当图元重新设置大小时触发（流程框自适应）<br>
   * 参数输入：eventSource, paramObj<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  textFigureResize: function () {
    var model = this.getModel();
    //改变之前的宽高
    // var oldWidth = model.getProperty().uiProperty.width;
    // var oldHeight = model.getProperty().uiProperty.height;

    var width = this.figure.width;
    var height = this.figure.height;

    // 当拉伸边框时，流程框里的文字可双击区域变大
    this.figure.label.cachedWidth = this.figure.width - 45;
    this.figure.label.cachedHeight = this.figure.height - 20;

    if (this.figure.hybridPorts.data[0]) {
      this.figure.hybridPorts.data[0].locator.x = 0;
      this.figure.hybridPorts.data[0].locator.y = height / 2;
    }
    if (this.figure.hybridPorts.data[1]) {
      this.figure.hybridPorts.data[1].locator.x = width;
      this.figure.hybridPorts.data[1].locator.y = height / 2;
    }
    if (this.figure.hybridPorts.data[2]) {
      this.figure.hybridPorts.data[2].locator.x = width / 2;
      this.figure.hybridPorts.data[2].locator.y = 0;
    }
    if (this.figure.hybridPorts.data[3]) {
      this.figure.hybridPorts.data[3].locator.x = width / 2;
      this.figure.hybridPorts.data[3].locator.y = height;
    }
    if (this.figure.hybridPorts.data[4]) {
      this.figure.hybridPorts.data[4].locator.x = width / 4;
      this.figure.hybridPorts.data[4].locator.y = height;
    }
    this.model.setDimension(this.figure.width, this.figure.height, false, this);
    // console.log(this.model);
    this.figure.hybridPorts.each(function (i, port) {
      port.locator.relocate(i, port);
    });

    model.inputPorts.each(function (i, port) {
      port.property.modelProperty.locator.defaultX = port.property.modelProperty.locator.x;
      port.property.modelProperty.locator.defaultY = port.property.modelProperty.locator.y;
    });
    model.outputPorts.each(function (o, port) {
      port.property.modelProperty.locator.defaultX = port.property.modelProperty.locator.x;
      port.property.modelProperty.locator.defaultY = port.property.modelProperty.locator.y;
    });
    // console.log(this.figure);
    this.figure.repaint();
    // this.refreshTree(model,oldWidth,oldHeight);
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceEditPart.textFigureResize<br>
   * 函数功能：自定义器材、材料、试剂自适应<br>
   * 参数输入：eventSource, paramObj<br>
   * 参数输出：无<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  CustomFigureResize: function (eventSource, paramObj) {
    var model = this.getModel();
    var width = this.figure.width;
    var height = this.figure.height;

    // 随着框的大小，连线端口也进行自适应变化
    if (this.figure.hybridPorts.data[0]) {
      this.figure.hybridPorts.data[0].locator.x = 0;
      this.figure.hybridPorts.data[0].locator.y = height / 2;
    }
    if (this.figure.hybridPorts.data[1]) {
      this.figure.hybridPorts.data[1].locator.x = width;
      this.figure.hybridPorts.data[1].locator.y = height / 2;
    }
    if (this.figure.hybridPorts.data[2]) {
      this.figure.hybridPorts.data[2].locator.x = width / 2;
      this.figure.hybridPorts.data[2].locator.y = 0;
    }
    if (this.figure.hybridPorts.data[3]) {
      this.figure.hybridPorts.data[3].locator.x = width / 2;
      this.figure.hybridPorts.data[3].locator.y = height;
    }
    if (this.figure.hybridPorts.data[4]) {
      this.figure.hybridPorts.data[4].locator.x = width / 4;
      this.figure.hybridPorts.data[4].locator.y = height;
    }
    // 修改自定义器件图像的宽度、高度
    this.model.property.uiProperty.imageWidth = this.figure.width;
    this.model.property.uiProperty.imageHeight = this.figure.height;
    this.model.property.imageProperty.width = this.figure.width;
    this.model.property.imageProperty.height = this.figure.height;

    this.model.setDimension(this.figure.width, this.figure.height, false, this);
    this.figure.hybridPorts.each(function (i, port) {
      port.locator.relocate(i, port);
    });

    model.inputPorts.each(function (i, port) {
      port.property.modelProperty.locator.defaultX = port.property.modelProperty.locator.x;
      port.property.modelProperty.locator.defaultY = port.property.modelProperty.locator.y;
    });
    model.outputPorts.each(function (o, port) {
      port.property.modelProperty.locator.defaultX = port.property.modelProperty.locator.x;
      port.property.modelProperty.locator.defaultY = port.property.modelProperty.locator.y;
    });
    // 设置名称figure的位置
    // console.log(this.figure.devNameFigure.x);
    // console.log(this.figure.devNameFigure.y);
    // this.figure.devNameFigure.x = this.figure.width/2;
    // this.figure.devNameFigure.y = this.figure.height;
    // console.log(this.figure.devNameFigure.x);
    // console.log(this.figure.devNameFigure.y);
    // this.figure.setPosition(this.figure.x,this.figure.y,false);
    this.figure.repaint();
  },
});

//上一个添加的一级节点
window.lastFNode = null;
//上一个添加的二级节点
window.lastSNode = null;
